//定义变量a、b、c,分别用来获取用户名，用户密码和用户角色的值
var a,b,c;

//用户框失去焦点后验证value值
function oBlur_1() {
    a = document.getElementById("name").value;
    if (a == "") { //用户框value值为空
        document.getElementById("remind_1").innerHTML = "用户名不能为空！".fontcolor("red");
        document.getElementById("change_margin_1").style.marginBottom = 1 + "px";
    } else { //用户框value值不为空
        document.getElementById("remind_1").innerHTML = "";
        document.getElementById("change_margin_1").style.marginBottom = 19 + "px";
    }
}


//用户框获得焦点的隐藏提醒
function oFocus_1() {
    document.getElementById("remind_1").innerHTML = "";
    document.getElementById("change_margin_1").style.marginBottom = 19 + "px";
}


window.onload = function(){

    var index = parent.layer.getFrameIndex(window.name);

    $('#saveUser').click(function () {
        var name = $("#name").val();
        var introduction = $("#introduction").val();
        var checkusercode="";
        var temp="";
        /*for(var i=1;i<8;i++){
            if(document.getElementById("code_"+i).checked==true){
                checkusercode=checkusercode+temp+$("#code_"+i).val();
                temp="#";
            }
        }*/
        
        checkusercode = $('input[type="checkbox"][name="code"]:checked').map(function () {
            return $(this).val();
        }).get().join("#");

        if(name==""||introduction==""||checkusercode==""){
            parent.layer.confirm('关键信息未全，不能添加！',{btn:['确定']});
        }else {
            $.ajax({
                url: constUrl + "RoleServlet",
                type: 'post',
                data: {
                    operateType: "add",
                    name: name,
                    introduction: introduction,
                    power_code:checkusercode
                },
                dataType: 'json',
                success: function (dataText) {
                    console.log(dataText.result);
                    if (dataText.result) {
                        parent.layer.confirm('添加成功！', {
                            btn: ['确定']
                        }, function () {
                            parent.location.reload(index);
                            parent.layer.close(index);
                        })
                    }
                },

                complete: function () {
                },
                error: function () {

                }
            });
        }
    });

    $('#closeIframe').click(function(){
        parent.layer.close(index);
    });
}
